/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.variable.dtgenerator.api.variableinterface;

import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.utils.ExpressionUtils;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.designtime.api.variable.CommonVariableEntity;
import com.inspur.edp.cef.generator.apiGenerator.dataType.entityInterface.resourceInfo.ResourceInfoCtorGenerator;
import com.inspur.edp.cef.spi.entity.resourceInfo.builinImpls.CefModelResInfoImpl;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;

public class VariableResInfoCtorGenerator extends ClassMethodGenerator {

  private final CommonVariableEntity dataType;
  private final String className;

  public VariableResInfoCtorGenerator(String className, CommonVariableEntity dataType) {
    this.className = className;
    this.dataType = dataType;
  }

  @Override
  protected final TypeInfo getReturnType() {
    return null;
  }

  @Override
  protected final String getMethodName() {
    return this.className;
  }

  @Override
  protected final ArrayList<ModifierKeyword> getAccessModifiers() {
    ArrayList<ModifierKeyword> list = new ArrayList();
    list.add(ModifierKeyword.PUBLIC_KEYWORD);
    return list;
  }

  @Override
  protected ArrayList<ParameterInfo> getParameterCollection() {
    return null;
  }

  @Override
  protected final boolean buildIsConstructor() {
    return true;
  }

  @Override
  protected final Block buildMethodBody() {
    Block block = this.ast.newBlock();
    SuperConstructorInvocation superConstructorInvocation = this.ast.newSuperConstructorInvocation();
    superConstructorInvocation.arguments().add(ExpressionUtils.getStringLiteral(this.ast, this.dataType.getCode()));
    superConstructorInvocation.arguments().add(ExpressionUtils.getStringLiteral(this.ast, this.dataType.getI18nResourceInfoPrefix()));
    block.statements().add(superConstructorInvocation);
    return block;
  }
}
